/**
 * Copyright (C) 2011-2012 GreenSoft S.A.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ar.com.greensoft.neosystem.model.address;

import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import ar.com.greensoft.neosystem.model.NamedEntity;

/**
 * @author Jorge E. Villaverde
 * @version 1.0.0
 * @since 1.0.0
 */
@Entity
@Table(name="localidad")
@Cacheable(value=false)
@Inheritance(strategy=InheritanceType.JOINED)
@NamedQueries({
	@NamedQuery(name=Localidad.FIND_ALL_QUERY_NAME, 
		query="SELECT p FROM Localidad p ORDER BY p.name"),
	@NamedQuery(name=Localidad.FIND_LIKE_NAME_QUERY_NAME, 
		query="SELECT p FROM Localidad p WHERE p.name LIKE :name"),
	@NamedQuery(name=Localidad.FIND_BY_NAME_QUERY_NAME, 
		query="SELECT p FROM Localidad p WHERE p.name = :name"),
	@NamedQuery(name=Localidad.FIND_BY_PROVINCIA_QUERY_NAME, 
		query="SELECT p FROM Localidad p WHERE p.provincia = :provincia ORDER BY p.name"),
	@NamedQuery(name=Localidad.FIND_BY_PROVINCIA_NAME_QUERY_NAME, 
		query="SELECT l FROM Localidad l WHERE l.provincia = :provincia AND l.name = :name"),
	@NamedQuery(name=Localidad.COUNT_QUERY_NAME, 
		query="SELECT COUNT(p) FROM Localidad p")
})
public class Localidad extends NamedEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6623675667778173815L;
	
	public static final String FIND_LIKE_NAME_QUERY_NAME = "Localidad.findNameLike";
	public static final String FIND_ALL_QUERY_NAME = "Localidad.findAll";
	public static final String FIND_BY_NAME_QUERY_NAME = "Localidad.findByName";
	public static final String FIND_BY_PROVINCIA_QUERY_NAME = "Localidad.findByProvincia";
	public static final String FIND_BY_PROVINCIA_NAME_QUERY_NAME = "Localidad.findByProvinciaName";
	public static final String COUNT_QUERY_NAME = "Localidad.count";


	@NotNull
	@ManyToOne
	@JoinColumn(name = "ID_PROVINCIA")
	private Provincia provincia;

	public Provincia getProvincia() {
		return provincia;
	}

	public void setProvincia(Provincia provincia) {
		this.provincia = provincia;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result
				+ ((provincia == null) ? 0 : provincia.hashCode());
		return result;
	}
}